package com.lc.afbx.adapters;

import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.application.MyApplication;
import com.lc.afbx.conn.GetApiIndexIndex;

import java.util.List;

/**
 * Created by Administrator on 2016/5/24.
 */
public class MyAdapter extends BaseAdapter {

    private List<GetApiIndexIndex.New> list;
    private Context context;

    public MyAdapter(Context context, List<GetApiIndexIndex.New> news) {

        this.list = news;
        this.context = context;
    }

    @Override
    public int getCount() {

        if (list == null) {
//            Log.d("hahaha", "哈哈哈list空了");
        }
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.item_navigation_listview, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder = new ViewHolder();

            holder.time = (TextView) convertView.findViewById(R.id.txttime_item_navigation);
            holder.title = (TextView) convertView.findViewById(R.id.txttitle_item_navigation);
            holder.imageView = (SimpleDraweeView) convertView.findViewById(R.id.img_item_navigation);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(list.get(position).title);
        holder.time.setText(list.get(position).posttime);

        Log.d("adapter", list.get(position).title);


//        Log.d("zheshi首页图片地址", "list.get(position).getPicurl()" + list.get(position).picurl);
//        BaseApplication.UtilAsyncListBitmap.get(list.get(position).picurl, holder.imageView, R.mipmap.jiamengjigou);

//        fresco下载
        holder.imageView.setImageURI(Uri.parse(list.get(position).picurl));

//        Volley下载
//        ImageLoader.ImageListener imageListener = imageLoader.getImageListener(holder.imageView, R.mipmap.ic_launcher, R.mipmap.ic_launcher);
//        imageLoader.get(list.get(position).getPicurl(), imageListener);


        return convertView;
    }

    class ViewHolder {

        private TextView title, time;
        private SimpleDraweeView imageView;
    }
}
